/* Eshm - SHM abstraction
 * Copyright (C) 2008-2012 Jorge Luis Zapata
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */
#include "Eshm.h"
#include "eshm_private.h"
/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
typedef struct _Eshm_Mempool
{
	Eina_List *segments;
} Eshm_Mempool;

static int _init = 0;
/*----------------------------------------------------------------------------*
 *                       The Eina's mempool interface                         *
 *----------------------------------------------------------------------------*/
static void *_eshm_init(__UNUSED__ const char *context,
                   __UNUSED__ const char *options,
                   va_list args)
{
	Eshm_Mempool *thiz;

	thiz = calloc(sizeof(Eshm_Mempool));
	return thiz;
}

static void _eshm_shutdown(void *data)
{
	Eshm_Mempool *thiz = data;

	free(thiz);
}

static void _eshm_free(void *data, void *element)
{
	Eshm_Mempool *thiz = data;
	Eshm_Segment *s = element;

}

static void *_eshm_alloc(void *data, unsigned int size)
{
	Eshm_Mempool *thiz = data;
	Eshm_Segment *s;
}

static Eina_Mempool_Backend _backend = {
	/* .name 		= */ "eshm",
	/* .init		= */ _eshm_init,
	/* .free		= */ _eshm_free,
	/* .alloc		= */ _eshm_alloc,
	/* .realloc		= */ NULL,
	/* .garbage_collect	= */ NULL,
	/* .statistics		= */ _eshm_statistics,
	/* .shutdown		= */ _eshm_shutdown,
	/* .repack		= */ NULL,
};
/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/
int eshm_eina_init(void)
{
	if (!_init++)
	{
		eina_mempool_register(&_backend);
	}
	return _init;
}

int eshm_eina_shutdown(void)
{
	if (--_init != 0)
		return _init;
	eina_mempool_unregister(&_backend);
	return _init;
}
/*============================================================================*
 *                                   API                                      *
 *============================================================================*/

